{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3e1ccbae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pyecharts\n",
      "  Downloading pyecharts-1.9.1-py3-none-any.whl (135 kB)\n",
      "Collecting simplejson\n",
      "  Downloading simplejson-3.17.6-cp38-cp38-win_amd64.whl (75 kB)\n",
      "Requirement already satisfied: jinja2 in c:\\programdata\\anaconda3\\lib\\site-packages (from pyecharts) (2.11.3)\n",
      "Collecting prettytable\n",
      "  Downloading prettytable-2.4.0-py3-none-any.whl (24 kB)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in c:\\programdata\\anaconda3\\lib\\site-packages (from jinja2->pyecharts) (1.1.1)\n",
      "Requirement already satisfied: wcwidth in c:\\programdata\\anaconda3\\lib\\site-packages (from prettytable->pyecharts) (0.2.5)\n",
      "Installing collected packages: simplejson, prettytable, pyecharts\n",
      "Successfully installed prettytable-2.4.0 pyecharts-1.9.1 simplejson-3.17.6\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3e50e91d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Bar\n",
    "from pyecharts.faker import Faker\n",
    "from pyecharts.globals import ThemeType\n",
    "\n",
    "c = (\n",
    "    Bar({\"theme\": ThemeType.MACARONS})\n",
    "    .add_xaxis([\"Alex\",\"XiaoMing\",\"Xiaohu\",\"Marry\",\"Jack\",\"Jan\",\"Lihua\"])\n",
    "    .add_yaxis(\"一千米\", [3.45,4.15,3.56,3.20,4.00,4.00,4.20])\n",
    "    .add_yaxis(\"立定跳远\", [2.5,2.6,2.4,2.3,2.5,2.4,2.45])\n",
    "    .set_global_opts(\n",
    "        title_opts={\"text\": \"Bar-通过 dict 进行配置\", \"subtext\": \"我也是通过 dict 进行配置的\"}\n",
    "    )\n",
    "    .render(\"bar_base_dict_config.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2ff3dbdd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['周一', '周二', '周三', '周四', '周五', '周六', '周日']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Faker.choose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e58efafa",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Alex\",\"XiaoMing\",\"Xiaohu\",\"Marry\",\"Jack\",\"Jan\",\"Lihua\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2b65381c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[111, 117, 104, 27, 146, 38, 60]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Faker.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d9d02e51",
   "metadata": {},
   "outputs": [],
   "source": [
    "一千米 = [3.45,4.15,3.56,3.20,4.00,4.00,4.20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a369e20d",
   "metadata": {},
   "outputs": [],
   "source": [
    "立定跳远 = [2.5,2.6,2.4,2.3,2.5,2.4,2.45]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f98e7415",
   "metadata": {},
   "source": [
    "* 实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "16add3a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\Administrator\\\\Desktop\\\\2021-2022-01\\\\interactive-media-production\\\\calendar_heatmap.html'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "import datetime\n",
    "\n",
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Calendar\n",
    "\n",
    "\n",
    "begin = datetime.date(2017, 1, 1)\n",
    "end = datetime.date(2017, 12, 31)\n",
    "data = [\n",
    "    [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]\n",
    "    for i in range((end - begin).days + 1)\n",
    "]\n",
    "\n",
    "(\n",
    "    Calendar(init_opts=opts.InitOpts(width=\"1600px\", height=\"1000px\"))\n",
    "    .add(\n",
    "        series_name=\"\",\n",
    "        yaxis_data=data,\n",
    "        calendar_opts=opts.CalendarOpts(\n",
    "            pos_top=\"120\",\n",
    "            pos_left=\"30\",\n",
    "            pos_right=\"30\",\n",
    "            range_=\"2017\",\n",
    "            yearlabel_opts=opts.CalendarYearLabelOpts(is_show=False),\n",
    "        ),\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(pos_top=\"30\", pos_left=\"center\", title=\"2017年步数情况\"),\n",
    "        visualmap_opts=opts.VisualMapOpts(\n",
    "            max_=20000, min_=500, orient=\"horizontal\", is_piecewise=False\n",
    "        ),\n",
    "    )\n",
    "    .render(\"calendar_heatmap.html\")\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3d6e263d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\Administrator\\\\Desktop\\\\2021-2022-01\\\\interactive-media-production\\\\calendar_heatmap.html'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "import datetime\n",
    "\n",
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Calendar\n",
    "\n",
    "\n",
    "begin = datetime.date(2021, 1, 1)\n",
    "end = datetime.date(2021, 12, 31)\n",
    "data = [\n",
    "    [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]\n",
    "    for i in range((end - begin).days + 1)\n",
    "]\n",
    "\n",
    "(\n",
    "    Calendar(init_opts=opts.InitOpts(width=\"1600px\", height=\"1000px\"))\n",
    "    .add(\n",
    "        series_name=\"\",\n",
    "        yaxis_data=data,\n",
    "        calendar_opts=opts.CalendarOpts(\n",
    "            pos_top=\"120\",\n",
    "            pos_left=\"30\",\n",
    "            pos_right=\"30\",\n",
    "            range_=\"2021\",\n",
    "            yearlabel_opts=opts.CalendarYearLabelOpts(is_show=False),\n",
    "        ),\n",
    "    )\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(pos_top=\"30\", pos_left=\"center\", title=\"2021年步数情况\"),\n",
    "        visualmap_opts=opts.VisualMapOpts(\n",
    "            max_=20000, min_=500, orient=\"horizontal\", is_piecewise=False\n",
    "        ),\n",
    "    )\n",
    "    .render(\"calendar_heatmap.html\")\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d914334f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
